package com.sk.bilibili.model.fragment.live;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.bean.Danmu;
import com.sk.bilibili.bean.Member;
import com.sk.bilibili.callBack.RequestCallBack;
import com.sk.bilibili.mapper.MemberMapper;
import com.sk.bilibili.model.BaseModel;
import com.sk.bilibili.other.BiliBiliProperty;
import com.sk.bilibili.utils.DanmuUtils;
import com.sk.bilibili.utils.DataUtils;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.live.InteractiveFragment;

public class InteractiveModel extends BaseModel<InteractiveFragment> {

    @Autowired
    BiliBiliProperty property;
    @Autowired
    MemberMapper memberMapper;

    public String getUrl(Integer liveId) {
        String baseUrl = property.getString("baseUrl").substring(4);
        return String.format("ws%slive/%d",baseUrl,liveId);
    }

    public Danmu createDanmu(String content) {
        Danmu danmu = new Danmu();
        danmu.setMemberId(DataUtils.getMemberId());
        danmu.setColor(DanmuUtils.getRandomColor());
        danmu.setContent(content);
        danmu.setType(DanmuUtils.getRandomType());
        return danmu;
    }

    public void loadMember() {
        RequestUtils.process(memberMapper.getMember(DataUtils.getMemberId()),
                member -> view.loadMemberSuccess(member));
    }

}